<?php
/**
 * Created by PhpStorm.
 * User: ZhangWei
 * Date: 2018/3/19
 * Time: 16:00
 */

namespace App\Http\Controllers\Api\V1;


use App\Helpers\FileTool;
use App\Http\Resources\QrPosterCollection;
use App\Logic\ShareLogic;
use App\Models\Channel;
use App\Models\Doc;
use App\Models\Lecture;
use App\Models\QrPoster;

class ShareController extends BaseController
{
    public function share_card()
    {
        $type = request('type', 'doc');
        $card = QrPoster::query()->where('type', $type)->orderByDesc('order')->get();
        $data = QrPosterCollection::make($card);
        return $this->success($data);
    }

    /**
     * @return mixed
     * @throws \App\Exceptions\ApiException
     */
    public function change_theme()
    {
        $id = $this->getId();
        $t_id = $this->getId('t_id');
        $type = request('type', 'lecture');
        $qr_poster = QrPoster::query()->where('type', $type)->findOrFail($t_id);
        $user = $this->getUser();
        switch ($type) {
            case 'doc':
                $doc = Doc::query()->findOrFail($id);
                $title = $doc->title;
                break;
        }


        $qr_code = ShareLogic::getXcxQr($type, $doc, $user);


        $card = FileTool::shareCard($qr_poster, false, false, $title, false, false, false, $qr_code);

        return $this->success($card);
    }

}